package com.qf.smartdevice.tasks;

import com.qf.smartdevice.events.enums.DeviceStatusCheckEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author 王博康
 * @version 1.0
 * @project devicemanagementsystem
 * @description: TODO
 * @date 2022/3/27 18:22 星期日
 */
@Component
@EnableScheduling
public class DeviceStatusCheckTask {

    private ApplicationContext context;

    @Autowired
    public void setContext(ApplicationContext context) {
        this.context = context;
    }

    @Scheduled(fixedRate = 31000)
    public void checkStatus(){
        //定时通知websocket检查设备最后一次心跳时间
        context.publishEvent(new DeviceStatusCheckEvent());
    }
}
